package com.shigu.weixin.util;

import com.github.wxpay.extend.MyWxPayConfig;
import com.github.wxpay.sdk.IWXPayDomain;
import com.github.wxpay.sdk.WXPayConfig;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import org.apache.commons.io.IOUtils;
import org.springframework.core.io.ClassPathResource;

/**
 * @author 郭尔
 * @description 小程序配置
 * @date 2019/1/23 10:21
 */

public class XcxPayConfig extends WXPayConfig {
    private byte[] certData;
    public XcxPayConfig() throws IOException {
        ClassPathResource classPathResource = new ClassPathResource("1401424002_20180909_cert.p12");
        InputStream certStream = classPathResource.getInputStream();
        this.certData = IOUtils.toByteArray(certStream);
        certStream.read(this.certData);
        certStream.close();
    }

    public String getAppID() {
        return "wx5866f3281a8a15be";
    }

    public String getMchID() {
        return "1401424002";
    }

    public String getKey() {
        return "8d84152a0d0410a05a7d7878bd342b53";
    }

    public InputStream getCertStream() {
        ByteArrayInputStream certBis = new ByteArrayInputStream(this.certData);
        return certBis;
    }

    public int getHttpConnectTimeoutMs() {
        return 8000;
    }

    public int getHttpReadTimeoutMs() {
        return 10000;
    }

    public IWXPayDomain getWXPayDomain() {
        return new IWXPayDomain() {
            public void report(String domain, long elapsedTimeMillis, Exception ex) {
            }

            public DomainInfo getDomain(WXPayConfig config) {
                return new DomainInfo("api.mch.weixin.qq.com", true);
            }
        };
    }
}
